package cn.clwxy.gdz.service;

import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import cn.clwxy.gdz.entity.Student;
import cn.clwxy.gdz.entity.Teacher;
import cn.clwxy.gdz.util.BaseDao;

public class LoginServiceImpl extends BaseDao implements LoginService{

	@Override
	public boolean isTeacher(String login_phone) {
		String sql="SELECT count(teacherId) from teacher WHERE teacherPhone=? AND isDelete=0";
		int resu=super.queryColumn(sql, new ScalarHandler(), login_phone).intValue();
		if(resu>0){
			return true;
		}
		return false;
	}

	@Override
	public boolean isStudent(String login_phone) {
		String sql="SELECT count(studentId) from student WHERE studentPhone=? AND isDelete=0";
		int resu=super.queryColumn(sql, new ScalarHandler(), login_phone).intValue();
		if(resu>0){
			return true;
		}
		return false;	}
	@Override
	public Teacher getTeaher(String login_phone, String login_pwd) {
		String sql="SELECT teacherId id,teacherRealName realName from teacher WHERE teacherPhone=? AND teacherPwd=? AND isDelete=0 GROUP  BY teacherPhone ";
		return super.querySingle(sql, new BeanHandler<Teacher>(Teacher.class), login_phone,login_pwd);
	}

	@Override
	public Student getStudent(String login_phone, String login_pwd) {
		String sql="SELECT studentId,studentName from student WHERE studentPhone=? AND studentPwd=? AND isDelete=0" ;
		return super.querySingle(sql, new BeanHandler<Student>(Student.class), login_phone,login_pwd);
	}

	@Override
	public Integer getStudentIdByPhone(String studentPhone) {
		String sql="SELECT studentId from student WHERE studentPhone=? AND isDelete=0";
		Student student=super.querySingle(sql, new BeanHandler<Student>(Student.class), studentPhone);
		Integer id=student.getStudentId();
		System.out.println(id);
		Integer studentId=id.intValue();
		System.out.println(studentId);
		if(studentId>0){
			return studentId;
		}
		return 0;	
	}

}
